//
// Created by Tiany on 2021/6/18.
//
//顺序表测试函数
#include <stdio.h>
#include "SeqList.h"

static int SeqListTest() {
    /*顺序表部分*/
    PSeqList pSeqList;/*定义顺序表*/
    struct DataType x1, x2, x3;
    x1.n = 16;
    x2.n = 15;
    x3.n = 33;
    pSeqList = createNullList_seq(20);/*创建表长为20的顺序表*/
    printf("顺序表状态（1为空，0为非空）:%d\n", isNullList_seq(pSeqList));
    struct DataType a[] = {10, 15, 4, 45, 561, 47, 85, 46, 32};
    int length = (sizeof(a) / sizeof(a[0]));/*获取数组长度*/
    writeList_seq(pSeqList, a, length);/*将数组写入顺序表*/
    printf("元素%d下标为：%d\n", x2.n, locate_seq(pSeqList, x2));
    readList_seq(pSeqList);/*读取并打印顺序表*/

    insertPre_seq(pSeqList, 3, x1);/* 在下标3之前插入元素x2 */
    printf("\n插入%d后\n", x1.n);
    readList_seq(pSeqList);

    insertPost_seq(pSeqList, 4, x3);/*在下标4之后插入元素x3*/
    printf("\n插入%d后\n", x3.n);
    readList_seq(pSeqList);

    deleteP_seq(pSeqList, 6);/*删除下标为6的元素*/
    printf("\n删除下标为6的元素后\n");
    readList_seq(pSeqList);
    deleteV_seq(pSeqList, x2);/*删除元素x2*/
    printf("\n删除元素%d后\n", x2.n);
    readList_seq(pSeqList);

    /****************************************************/
    printf("\n************练习题**************\n");
    /*设有一线性表e=(e1,e2,e3...en)，其逆线性表定义为e'=(en,...e3,e2,e1),请设计一个算法，将顺序表表示的线性表逆置，要求逆线性表仍使用原线性表的空间*/
    struct DataType x[] = {10, 45, 165, 13, 46, 5, 0, 16, 13, 1, 5, 3, 13, 54, 5, 3, 23, 132, 5, 20, 30};
    int length2 = sizeof(x) / sizeof(x[0]);
    PSeqList pSeqList1 = createNullList_seq(length2 * 2);/*创建最大长度为两倍数据长度的顺序表*/
    writeList_seq(pSeqList1, x, length2);
    printf("\n逆置前：\n");
    readList_seq(pSeqList1);
    printf("\n逆置后：\n");
    sortSeq(pSeqList1);/*逆置顺序表*/
    readList_seq(pSeqList1);

    /*已知线性表a的长度为n，采用顺序结构，写一算法，删除顺序表中所有值为x的元素*/
    printf("\n删除所有元素%d\n",x[5].n);
    deleteAllV_seq(pSeqList1,x[5]);
    readList_seq(pSeqList1);

    return 0;
}
